﻿using System;
using NodeEditorFramework;
using UnityEngine;
using UnityEngine.Serialization;
using System.Collections.Generic;
using MainScene.Evt.Condition;
using Sirenix.Serialization;

/// <summary>
/// basic dialog node class, all other dialog nodes are derived from this
/// </summary>
[Node(true, "LevelMap/Base Dialog Node", new Type[] { typeof(LevelMapNodeCanvas) })]
public abstract class BaseStoryNode : Node
{
    public override bool AllowRecursion { get { return true; } }
    public abstract Type GetObjectType { get; }

    public override Vector2 MinSize { get { return new Vector2(350, 200); } }
    public override bool AutoLayout { get { return true; } }  //resizable renamed to autolayout?

    #region EventData
    [FormerlySerializedAs("events"),OdinSerialize]
    public MainScene.SceneEventData events;
    public string GetEventId {
        get { return events.eventId; }
    }
   

    #endregion

    public abstract bool IsBackAvailable();
    public abstract bool IsNextAvailable();


    ///check if the first connection of the specified port points to something
    protected bool IsAvailable(ConnectionPort port)
    {
        return port != null
            && port.connections != null && port.connections.Count > 0
            && port.connections[0].body != null
            && port.connections[0].body != default(Node);
    }

    ///return the dialog node pointed to by the first connection in the specified port
    protected BaseStoryNode getTargetNode(ConnectionPort port)
    {
        if (IsAvailable(port))
            return port.connections[0].body as BaseStoryNode;
        return null;
    }

    protected internal override void CopyScriptableObjects(Func<ScriptableObject, ScriptableObject> replaceSO)
    {
        base.CopyScriptableObjects(replaceSO);
    }
    protected internal override void OnAddConnection(ConnectionPort port, ConnectionPort connection)
    {
        base.OnAddConnection(port, connection);

     
    }
    protected internal override void OnDeleteConnection(ConnectionPort port, ConnectionPort remove)
    {
        base.OnDeleteConnection(port, remove);
       
    }
    protected override void OnCreate()
    {
        base.OnCreate();
    }
    protected internal override void OnDelete()
    {
        base.OnDelete();
    }
   
}

public class StoryBackType : ConnectionKnobStyle //: IConnectionTypeDeclaration
{
    public override string Identifier { get { return "StoryBack"; } }
    public override Color Color { get { return Color.yellow; } }
}

public class StoryForwardType : ValueConnectionType // : IConnectionTypeDeclaration
{
    public override string Identifier { get { return "StoryForward"; } }
    public override Type Type { get { return typeof(float); } }
    public override Color Color { get { return Color.cyan; } }
}

